#include "OutputReader.h"
#include <QThread>
#include <QDebug>

OutputReader::OutputReader(QProcess *process, QObject *parent)
    : QObject(parent), process(process), running(false)
{
}

OutputReader::~OutputReader()
{
}

void OutputReader::readOutput()
{
    running = true; // 确保在开始时设置 running 为 true
    while (running)
    {
        if (process->bytesAvailable() > 0)
        {
            QByteArray output = process->readAllStandardOutput();
            emit outputReceived(output);
        }
        QThread::msleep(100); // 每 100 毫秒检查一次
    }
}

void OutputReader::stopReading()
{
    running = false; // 设置标志为 false，退出循环
}

void OutputReader::startReading()
{
    running = true; // 重置 running 标志为 true
}
